﻿using System;
using System.Collections.Specialized;
using System.Globalization;

using DotNetNuke.Entities.Users;
using DotNetNuke.Security;
using DotNetNuke.Services.Tokens;


namespace DotNetNuke.Modules.UserDefinedTable
{


    public class FilteredNameValueCollectionPropertyAccess : IPropertyAccess
    {
        private System.Collections.Specialized.NameValueCollection NameValueCollection;

        public FilteredNameValueCollectionPropertyAccess(System.Collections.Specialized.NameValueCollection list)
        {
            this.NameValueCollection = list;
        }

        public string GetProperty(string strPropertyName, string strFormat, CultureInfo formatProvider, UserInfo AccessingUser, Scope AccessLevel, ref bool PropertyNotFound)
        {
            if (this.NameValueCollection != null)
            {
                string str2;
                string userInput = this.NameValueCollection[strPropertyName];
                if ( string.IsNullOrEmpty(strFormat) )
                    str2 = "g";
                
                else
                    str2 = string.Empty;
                
                if (userInput != null)
                {
                    PortalSecurity security = new PortalSecurity();
                    userInput = security.InputFilter(userInput, PortalSecurity.FilterFlag.NoScripting);
                    return security.InputFilter(PropertyAccess.FormatString(userInput, strFormat), PortalSecurity.FilterFlag.NoScripting);
                }
                PropertyNotFound = true;
            }
            return string.Empty;
        }

        public CacheLevel Cacheability
        {
            get
            {
                return CacheLevel.notCacheable;
            }
        }

        //public CacheLevel DotNetNuke.Services.Tokens.IPropertyAccess.Cacheability
        //{
        //    get
        //    {
        //        return CacheLevel.notCacheable;
        //    }
        //}
    }
}

